import uiautomator2 as u2
import uiautomator2.ext.htmlreport as htmlreport
from time import sleep
import time
import os
#com.bluephone
d = u2.connect('MT66-2WA-9D06127')

d.app_start("com.bluephone")
#用户使用
d(resourceId="com.bluephone:id/systemSet3").click()
d(resourceId="com.bluephone:id/data2").click()
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/iv_back").click()
#系统设置
d(resourceId="com.bluephone:id/systemSet4").click()
d(resourceId="android:id/input").click()
d.send_keys("330624", clear=True)
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/systemSet4").click()
d(resourceId="com.bluephone:id/spinner1").click()
d(resourceId="com.bluephone:id/tvName", text="浙江").click()
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/systemSet4").click()
d.send_keys("330624", clear=True)
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/systemSet4").click()
d(resourceId="com.bluephone:id/spinner2").click()
d(resourceId="com.bluephone:id/tvName", text="出码分离").click()
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/systemSet4").click()
d.send_keys("330624", clear=True)
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/systemSet4").click()
time.sleep(1)
d.swipe_ext("up")
d(resourceId="com.bluephone:id/collectmode4").click()   #点击科室装箱

d.keyevent('back')  #单击返回按钮



def scan(x):
    os.system("adb shell am broadcast -a android.intent.ACTION_DECODE_DATA --es barcode_string %s" % x)
    time.sleep(3)
scan("9999010001A1001")


#回收操作
d(resourceId="com.bluephone:id/tvRecover").click()
d(resourceId="com.bluephone:id/depart_name").click()
d(resourceId="com.bluephone:id/tvName", text="内科").click()

scan("9999010001B1048") #扫自动化科室
scan("9999010001A2080") #扫自动化护士


d.service("uiautomator").stop()